package org.computer.hibernate.artifacts;

import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * Data access object (DAO) for domain model class ComputerBasicInfo.
 * 
 * @see org.computer.hibernate.artifacts.ComputerBasicInfo
 * @author MyEclipse Persistence Tools
 */

public class ComputerBasicInfoDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory
			.getLog(ComputerBasicInfoDAO.class);

	// property constants
	public static final String COMPUTER_TYPE = "computerType";

	public static final String MANUFACTURER = "manufacturer";

	public static final String PRODUCT_MODEL = "productModel";

	public static final String CPU = "cpu";

	public static final String MEMORY = "memory";

	public static final String DISPLAYER = "displayer";

	public static final String WEIGHT = "weight";

	public static final String PRICE = "price";

	protected void initDao() {
		// do nothing
	}

	public void save(ComputerBasicInfo transientInstance) {
		log.debug("saving ComputerBasicInfo instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(ComputerBasicInfo persistentInstance) {
		log.debug("deleting ComputerBasicInfo instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ComputerBasicInfo findById(java.lang.Integer id) {
		log.debug("getting ComputerBasicInfo instance with id: " + id);
		try {
			ComputerBasicInfo instance = (ComputerBasicInfo) getHibernateTemplate()
					.get("org.computer.hibernate.artifacts.ComputerBasicInfo",
							id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(ComputerBasicInfo instance) {
		log.debug("finding ComputerBasicInfo instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ComputerBasicInfo instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from ComputerBasicInfo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByComputerType(Object computerType) {
		return findByProperty(COMPUTER_TYPE, computerType);
	}

	public List findByManufacturer(Object manufacturer) {
		return findByProperty(MANUFACTURER, manufacturer);
	}

	public List findByProductModel(Object productModel) {
		return findByProperty(PRODUCT_MODEL, productModel);
	}

	public List findByCpu(Object cpu) {
		return findByProperty(CPU, cpu);
	}

	public List findByMemory(Object memory) {
		return findByProperty(MEMORY, memory);
	}

	public List findByDisplayer(Object displayer) {
		return findByProperty(DISPLAYER, displayer);
	}

	public List findByWeight(Object weight) {
		return findByProperty(WEIGHT, weight);
	}

	public List findByPrice(Object price) {
		return findByProperty(PRICE, price);
	}

	public List findAll() {
		log.debug("finding all ComputerBasicInfo instances");
		try {
			String queryString = "from ComputerBasicInfo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ComputerBasicInfo merge(ComputerBasicInfo detachedInstance) {
		log.debug("merging ComputerBasicInfo instance");
		try {
			ComputerBasicInfo result = (ComputerBasicInfo) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ComputerBasicInfo instance) {
		log.debug("attaching dirty ComputerBasicInfo instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ComputerBasicInfo instance) {
		log.debug("attaching clean ComputerBasicInfo instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ComputerBasicInfoDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (ComputerBasicInfoDAO) ctx.getBean("ComputerBasicInfoDAO");
	}
}